导航菜单
首页 >  PDF Options  > PDF Basics – Quarto

PDF Basics – Quarto

PDF Basics Overview

Use the pdf format to create PDF output. For example:

---title: "My document"format: pdf:toc: truenumber-sections: truecolorlinks: true---

This example highlights a few of the options available for PDF output. This article covers these and other options in detail. See the PDF format reference for a complete list of all available options.

If you want to produce raw LaTeX output (a .tex file) rather than a PDF, all of the options documented here are still available (see the LaTeX Output section below for additional details).

Note

Note that while we will focus here exclusively on the use of LaTeX to create PDFs, Pandoc also has support for creating PDFs using ConTeXt, roff ms, or HTML (via wkhtmltopdf). See the Pandoc documentation on Creating a PDF for additional details.

Prerequisites

In order to create PDFs you will need to install a recent distribution of TeX. We recommend the use of TinyTeX (which is based on TexLive), which you can install with the following command:

Terminalquarto install tinytex

See the article on PDF Engines for details on using other TeX distributions and PDF compilation engines.

Document Class

Quarto uses KOMA Script document classes by default for PDF documents and books. KOMA-Script classes are drop-in replacements for the standard classes with an emphasis on typography and versatility.

For PDF documents this results in the following Pandoc options set by default:

format: pdf:documentclass: scrartclpapersize: letter

You can set documentclass to the standard article, report or book classes, to the KOMA Script equivalents scrartcl, scrreprt, and scrbook respectively, or to any other class made available by LaTeX packages you have installed.

Note

Setting your documentclass to either book or scrbook will automatically handle many of the common needs for printing and binding PDFs into a physical book (i.e., chapters start on odd pages, alternating margin sizes, etc).

See the Output Options section below for additional details on customizing LaTeX document options.

Table of Contents

Use the toc option to include an automatically generated table of contents in the output document. Use the toc-depth option to specify the number of section levels to include in the table of contents. The default is 3 (which means that level-1, 2, and 3 headings will be listed in the contents). For example:

toc: truetoc-depth: 2

You can customize the title used for the table of contents using the toc-title option:

toc-title: Contents

If you want to exclude a heading from the table of contents, add both the .unnumbered and .unlisted classes to it:

### More Options {.unnumbered .unlisted}Section Numbering

Use the number-sections option to number section headings in the output document. For example:

number-sections: true

Use the number-depth option to specify the deepest level of heading to add numbers to (by default all headings are numbered). For example:

number-depth: 3

To exclude an individual heading from numbering, add the .unnumbered class to it:

### More Options {.unnumbered}Syntax Highlighting

Pandoc will automatically highlight syntax in fenced code blocks that are marked with a language name. For example:

```python1 + 1```

Pandoc can provide syntax highlighting for over 140 different languages (see the output of quarto pandoc --list-highlight-languages for a list of all of them). If you want to provide the appearance of a highlighted code block for a language not supported, just use default as the language name.

You can specify the code highlighting style using highlight-style and specifying one of the supported themes. Supported themes include: arrow, pygments, tango, espresso, zenburn, kate, monochrome, breezedark, haddock, atom-one, ayu, breeze, dracula, github, gruvbox, monokai, nord, oblivion, printing, radical, solarized, and vim.

For example:

highlight-style: github

Highlighting themes can provide either a single highlighting definition or two definitions, one optimized for a light colored background and another optimized for a dark color background. When available, Quarto will automatically select the appropriate style based upon the code chunk background color’s darkness. You may always opt to specify the full name (e.g. atom-one-dark) to bypass this automatic behavior.

By default, code is highlighted using the arrow theme, which is optimized for accessibility. Here are examples of the arrow light and dark themes:

LightDark

Code Annotation

You can add annotations to lines of code in code blocks and executable code cells. See Code Annotation for full details.

Output Options

There are numerous options available for customizing PDF output, including:

Specifying document classes and their options

Including lists of figures and tables

Using the geometry and hyperref packages

Numerous options for customizing fonts and colors.

For example, here we use a few of these options:

---title: "My Document"format:pdf: documentclass: reportclassoption: [twocolumn, landscape]lof: truelot: truegeometry: - top=30mm - left=20mm - heightroundedmainfont: Times New Romancolorlinks: true---

See the Pandoc documentation on metadata variables for LaTeX for documentation on all available options.

Fonts

Using xelatex, the default engine, or the lualatex engine, you can specify fonts with the YAML options:

OptionDocument ElementsansfontHeadingsmainfontMain body textmonofontCodemathfontMathCJKmainfontThe CJK main font family

Values for these options should be the family name of system installed fonts. For example:

---format:pdf:mainfont: "Times New Roman"---

Fonts are set using the fontspec package. You can set additional font features using the corresponding options key. For example, you could set headings to the color #39729E:

---format:pdf:sansfont: "Open Sans"sansfontoptions:- Color=39729E---pdflatex

If you use the pdflatex engine, use the fontfamily option to specify a font from the The LaTeX Font Catalogue. For example:

---title: pdflatex fontsformat: pdf:pdf-engine: pdflatexfontfamily: anttor---Unicode Characters

By default, Quarto uses the xelatex engine to produce PDFs from LaTeX. xelatex has native support for unicode characters, but it is possible some customization will be required in order to properly typeset specific unicode characters. In particular, it is important that you use a font that supports the characters that you using in your document. To identify fonts on your system that support specific language characters, you can use the following command:

Terminalfc-list :lang= family

Where is a ISO 639 language code. For example, to see a list of fonts that support Japanese characters, use:

Terminalfc-list :lang=ja family

Select a font name from the list and use that as the document’s main font:

---title: Unicode testformat: pdfmainfont: "Hiragino Sans GB"---## Test Document青黑體簡體中文,ヒラギノ角

Another common example of Unicode characters are documents that include Greek symbols:

greek.qmd---format: pdf---## α```rα

相关推荐: